<?php

namespace App\Http\Resources;

use App\Models\Leader;
use App\Models\ReleaseLeader;
use App\Models\User;

class ProfitListResource extends Resource
{
    /**
     * Transform the resource collection into an array.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function toArray($request)
    {
        return [
            'username' => User::where('id', $this->user_id)->value('username'),
            'type' => $this->getType(),
            'profit' => bcadd($this->number, 0, 2),
            'time' => $this->time
        ];
    }

    private function getType()
    {
        switch ($this->type) {
            case '静态奖励释放':
                return '静态奖励';
            case '推荐奖励释放':
                return '推荐奖励';
            case '领导奖励释放':
                return '领导奖励';
            default:
                return $this->type;
        }
    }

    private function getUserName()
    {
        // switch ($this->type) {
        //     case '静态奖励释放':
        //         return User::where('id', $this->user_id)->value('username');
        //     case '推荐奖励释放':
        //         $leader = Leader::find($this->action_id);
        //         if ($leader) {
        //             return User::where('id', $leader->child_user_id)->value('username');
        //         } else {
        //             return '';
        //         }
        //     case '领导奖励释放':
        //         $releaseLeader = ReleaseLeader::find($this->action_id);
        //         if ($releaseLeader) {
        //             return User::where('id', $releaseLeader->child_user_id)->value('username');
        //         } else {
        //             return '';
        //         }
        //         return '';
        //     default:
        //         return '';
        // }
    }
}
